#pragma once

#include <mytypes.h>
#include <mythread.hxx>
#include <safeque.hxx>
#include <string>

#include "auto.hxx"

class TcpBridgeNet;
class MsgHandler;
class FileLog;
typedef struct tagBridgeMsg tBridgeMsg;
class TaskManager;

class BridgeConn : public Thread
{
    public:
        BridgeConn(const string& bridgehost, tUInt32 bridgeport, const string& myname, TaskManager* taskManager, FileLog* filelog = NULL);

		void Shutdown(void);
		/* \brief Sending attacking command to bridge server.
		* Param port :
		* Param atkType : 1 slowris attacking; 2 heavy attacking.
		**/
		void Attack(tUInt32 port, tUInt32 atkType, tUInt32 atkNum);
		void StopAttack(void);

		void Report(const string& results, tUInt32 tom);

    protected:
        
        virtual void Execute(Thread::Arg);

    private:
		void DisplayMsg(string msg, int level);
		void RegisterCli(void);

		const string _host;
        tUInt32 _port;

		const string _myname;

		 TaskManager* _taskmanager;

		SafeQue<tBridgeMsg*> _in_que;
        SafeQue<tBridgeMsg*> _out_que;

		void HandleMsg(tBridgeMsg* msg);
		//void HandleOut(void);

        bool _shutdown_requested;
        FileLog* _filelog;
};
